<html>
<head><meta charset="utf-8"><title>rust-analyzer#1243 · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer.231243.html">rust-analyzer#1243</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="165525625"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer%231243/near/165525625" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edwin Cheng <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer.231243.html#165525625">(May 13 2019 at 13:00)</a>:</h4>
<p>Just tried swaping <code>public_macro</code> and <code>local_macro</code> order did fix the issue <a href="https://github.com/rust-analyzer/rust-analyzer/issues/1243" target="_blank" title="https://github.com/rust-analyzer/rust-analyzer/issues/1243">#1243</a></p>
<p>Before:</p>
<div class="codehilite"><pre><span></span>    pub(crate) fn find_macro(&amp;self, name: &amp;Name) -&gt; Option&lt;MacroDefId&gt; {
        self.public_macros.get(name).or(self.local_macros.get(name)).map(|it| *it)
    }
</pre></div>


<p>After:</p>
<div class="codehilite"><pre><span></span>    pub(crate) fn find_macro(&amp;self, name: &amp;Name) -&gt; Option&lt;MacroDefId&gt; {
         self.local_macros.get(name).or(self.public_macros.get(name)).map(|it| *it)
    }
</pre></div>


<p>However, i agreed we need to be just more principled with macro resolution as <span class="user-mention" data-user-id="133169">@matklad</span> said. So the question is , do i submit a PR for this swapping hotfix ? Or waiting for the better name resolution implementation ?</p>



<a name="165527538"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer%231243/near/165527538" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer.231243.html#165527538">(May 13 2019 at 13:25)</a>:</h4>
<p>Could also add a test for this? I am all for PR!</p>



<a name="165633018"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer%231243/near/165633018" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edwin Cheng <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer.231243.html#165633018">(May 14 2019 at 15:41)</a>:</h4>
<blockquote>
<p>Could also add a test for this? I am all for PR!</p>
</blockquote>
<p>I found that i don't actually know why that fix the issue <span aria-label="joy" class="emoji emoji-1f602" role="img" title="joy">:joy:</span> . So i start to study how current macro name resolution works and want  to try  implementing instead of proper macro scopes in <code>DefMap</code>.</p>



<a name="165633392"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer%231243/near/165633392" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edwin Cheng <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer.231243.html#165633392">(May 14 2019 at 15:45)</a>:</h4>
<p>But i have a few questions:</p>
<p>In <code>collector.rs</code> :</p>
<div class="codehilite"><pre><span></span><span class="w"> </span><span class="k">fn</span> <span class="nf">resolve_macros</span><span class="p">(</span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="bp">self</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">ReachedFixedPoint</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">       </span><span class="p">......</span><span class="w"></span>
<span class="w">        </span><span class="n">macros</span><span class="p">.</span><span class="n">retain</span><span class="p">(</span><span class="o">|</span><span class="p">(</span><span class="n">module_id</span><span class="p">,</span><span class="w"> </span><span class="n">ast_id</span><span class="p">,</span><span class="w"> </span><span class="n">path</span><span class="p">)</span><span class="o">|</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">            </span><span class="p">.......</span><span class="w"></span>
<span class="w">        </span><span class="p">});</span><span class="w"></span>

<span class="w">        </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="n">module_id</span><span class="p">,</span><span class="w"> </span><span class="n">macro_call_id</span><span class="p">,</span><span class="w"> </span><span class="n">macro_def_id</span><span class="p">)</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">resolved</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">            </span><span class="bp">self</span><span class="p">.</span><span class="n">collect_macro_expansion</span><span class="p">(</span><span class="n">module_id</span><span class="p">,</span><span class="w"> </span><span class="n">macro_call_id</span><span class="p">,</span><span class="w"> </span><span class="n">macro_def_id</span><span class="p">);</span><span class="w"></span>
<span class="w">        </span><span class="p">}</span><span class="w"></span>
<span class="w">        </span><span class="n">res</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>


<p>Why we do not to set back the retained <code>macros</code> back in <code>self.unexpanded_macros</code> ?</p>



<a name="165633716"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer%231243/near/165633716" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edwin Cheng <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer.231243.html#165633716">(May 14 2019 at 15:49)</a>:</h4>
<p>And if i understand correctly, current implementation do not support old style external crate + <code>#[macro_use]</code> combo , is it correct ?</p>



<a name="165633753"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer%231243/near/165633753" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer.231243.html#165633753">(May 14 2019 at 15:49)</a>:</h4>
<p>that... looks like a bug?</p>



<a name="165633816"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer%231243/near/165633816" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer.231243.html#165633816">(May 14 2019 at 15:50)</a>:</h4>
<p>we should swap unexpanded macros back</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>